
package com.stchou.superbrowser.activity;

import com.stchou.superbrowser.ui.widget.SuperTabMenu;
import com.stchou.superbrowser.ui.widget.SuperToast;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class LoginActivity extends Activity
{
    
    SuperTabMenu.MenuBodyAdapter []bodyAdapter=new SuperTabMenu.MenuBodyAdapter[3];  
    SuperTabMenu.MenuTitleAdapter titleAdapter;  
    SuperTabMenu SuperTabMenu;  
    private int selTitle;
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        //设置分页栏的标题   
        titleAdapter = new SuperTabMenu.MenuTitleAdapter(this, new String[] { "常用",  
                "设置", "工具" }, 16, 0xFF222222,Color.LTGRAY,Color.WHITE);  
        //定义每项分页栏的内容   
        bodyAdapter[0]=new SuperTabMenu.MenuBodyAdapter(this,new String[] { "常用1", "常用2", "常用1", "常用2","常用1", "常用2","常用1", "常用2","常用1", "常用2",},   
                 new int[] { R.drawable.menu_test,  
                R.drawable.menu_bookmark,R.drawable.menu_test,  
                R.drawable.menu_bookmark,R.drawable.menu_test,  
                R.drawable.menu_bookmark,R.drawable.menu_test,  
                R.drawable.menu_bookmark,R.drawable.menu_test,  
                R.drawable.menu_bookmark},13, 0xFFFFFFFF);  
           
        bodyAdapter[1]=new SuperTabMenu.MenuBodyAdapter(this,new String[] { "设置1", "设置2",  
                    "设置3"}, new int[] { R.drawable.menu_edit,  
                    R.drawable.menu_delete, R.drawable.menu_fullscreen},13, 0xFFFFFFFF);  
           
        bodyAdapter[2]=new SuperTabMenu.MenuBodyAdapter(this,new String[] { "工具1", "工具2",  
                    "工具3", "工具4" }, new int[] { R.drawable.menu_copy,  
                    R.drawable.menu_cut, R.drawable.menu_normalmode,  
                    R.drawable.menu_quit },13, 0xFFFFFFFF);  
           
           
        SuperTabMenu=new SuperTabMenu(this,  
                 new TitleClickEvent(),  
                 new BodyClickEvent(),  
                 titleAdapter,  
                 0x55123456,//SuperTabMenu的背景颜色   
                 R.style.PopupAnimation);//出现与消失的动画   
           
         SuperTabMenu.update();  
         SuperTabMenu.SetTitleSelect(0);  
         SuperTabMenu.SetBodyAdapter(bodyAdapter[0]);  
    }  
      
    class TitleClickEvent implements OnItemClickListener{  
        @Override  
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,  
                long arg3) {  
            selTitle=arg2;  
            SuperTabMenu.SetTitleSelect(arg2);  
            SuperTabMenu.SetBodyAdapter(bodyAdapter[arg2]);  
        }  
    }  
      
    class BodyClickEvent implements OnItemClickListener{  
        @Override  
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,  
                long arg3) {  
            SuperTabMenu.SetBodySelect(arg2,Color.GRAY);  
            String str="第"+String.valueOf(selTitle)+"栏/n/r"  
            +"第"+String.valueOf(arg2)+"项";  
            SuperToast.makeLongText(LoginActivity.this, str).show();  
              
        }  
          
    }  
    @Override  
    /** 
     * 创建MENU 
     */  
    public boolean onCreateOptionsMenu(Menu menu) {  
        menu.add("menu");// 必须创建一项   
        return super.onCreateOptionsMenu(menu);  
    }  
    @Override  
    /** 
     * 拦截MENU 
     */  
    public boolean onMenuOpened(int featureId, Menu menu) {  
        if (SuperTabMenu != null) {  
            if (SuperTabMenu.isShowing())  
                SuperTabMenu.dismiss();  
            else {  
                SuperTabMenu.showAtLocation(findViewById(R.id.login_layout),  
                        Gravity.BOTTOM, 0, 0);  
                
            }  
        }  
        return false;// 返回为true 则显示系统menu   
    }  

}
